home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog3.arj / UOPTIONS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.8 KB  |  98 lines

  1. {******************************************************************}
  2. {                                                                  }
  3. {     Mancala                                                      }
  4. {     Turbo Pascal for Windows                                     }
  5. {     Copyright (c) 1991 by Swan Software. All rights reserved.    }
  6. {                                                                  }
  7. {******************************************************************}
  8.  
  9. { uoptions.pas -- Options dialog for Mancala }
  10.  
  11. unit UOptions;
  12.  
  13. interface
  14.  
  15. uses WinTypes, WinProcs, WObjects, UGlobals, Idents;
  16.  
  17. const
  18.  
  19.   ppcLen = 2;     { Length of Pepples per cup input field }
  20.  
  21. type
  22.  
  23.   POptionsRec = ^OptionsRec;  { Pointer to OptionsRec record }
  24.   OptionsRec = record
  25.     PPCLine: array[0 .. ppcLen] of Char;
  26.   end;
  27.  
  28.   POptDialog = ^OptDialog;
  29.   OptDialog = object(TDialog)
  30.     DataPointer: POptionsRec;
  31.     constructor Init(AParent: PWindowsObject; AName: PChar;
  32.       P: POptionsRec);
  33.     procedure SetupWindow; virtual;
  34.     procedure Ok(var Msg: TMessage);
  35.       virtual id_First + id_Ok;
  36.   end;
  37.  
  38.  
  39. implementation
  40.  
  41.  
  42. {- Initialize edit control identified by CtrlID with text in Buffer.
  43. HDlg is the dialog window handle; MaxLen is the maximum number of
  44. characters that can be entered into the control.}
  45.  
  46. procedure SetText(HDlg: HWnd; CtrlID: Word; Buffer: PChar; MaxLen: Word);
  47. begin
  48.   SendDlgItemMessage(HDlg, CtrlID, wm_SetText, 0, LongInt(Buffer));
  49.   SendDlgItemMessage(HDlg, CtrlID, em_LimitText, MaxLen, 0);
  50. end;
  51.  
  52.  
  53. {- Retrieve text from edit control identified by CtrlID. Text is
  54. copied to the array addressed by Buffer. MaxLen equals the maximum
  55. number of bytes to copy, including the null terminator.}
  56.  
  57. procedure GetText(HDlg: HWnd; CtrlID: Word; Buffer: PChar; MaxLen: Word);
  58. begin
  59.   SendDlgItemMessage(HDlg, CtrlID, wm_GetText, MaxLen, LongInt(Buffer));
  60. end;
  61.  
  62.  
  63. {- Construct OptDialog instance. P addresses dialog data record. }
  64.  
  65. constructor OptDialog.Init(AParent: PWindowsObject; AName: PChar;
  66.   P: POptionsRec);
  67. begin
  68.   TDialog.Init(AParent, AName);
  69.   DataPointer := P;  { Save pointer to caller's dialog record }
  70. end;
  71.  
  72.  
  73. {- Prepare initial control values }
  74.  
  75. procedure OptDialog.SetupWindow;
  76. begin
  77.   TDialog.SetupWindow;
  78.   SetText(HWindow, op_PebblesPerCup, DataPointer^.PPCLine, ppcLen);
  79. end;
  80.  
  81.  
  82. {- Respond to Ok button }
  83.  
  84. procedure OptDialog.Ok(var Msg: TMessage);
  85. begin
  86.   GetText(HWindow, op_PebblesPerCup, DataPointer^.PPCLine, ppcLen + 1);
  87.   TDialog.Ok(Msg);
  88. end;
  89.  
  90.  
  91. end.
  92.  
  93.  
  94. { ----------------------------------------------------------------
  95.   Copyright (c) 1991 by Swan Software. All rights reserved.
  96.   Revision 1.00    Date: 8/21/1991
  97.   ---------------------------------------------------------------- }
  98.